﻿using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;

namespace CommonLib.Audio {
	public class AudioManagerBase : ISingleton<AudioManagerBase>, CommonLib.Save.IBinaryIO
	{
		#region 单例
		//static public AudioManagerBase Instance
		//{
		//	get
		//	{
		//		if (null == m_Instance)
		//			Debug.LogError("未初始化AudioManager组件");
		//		return m_Instance;
		//	}
		//}

		//static AudioManagerBase m_Instance;
		#endregion
		//IAduioSystem的实现类
		public IAudioSystem System
		{
			get
			{
				if(null == system)
				{
					//初始化AudioSystem
					system = new AudioSystem();
					system.Init(this, new List<string>() { "BGM", "Ambience"});
				}
				return system;
			}

			set
			{

			}
		}
		IAudioSystem system;
		#region  Property And Field
		public List<string> SubManagerLabel = new List<string>();

		#endregion


		#region 对于提供的功能	
		//公有
		public void Init()
		{
			//Instance = this;
			//for (int index = 0; index < SubManagerLabel.Count; index++)
			//{
			//	GameObject sub = new GameObject(SubManagerLabel[index]);
			//	sub.transform.parent = this.transform;
			//	Group.Add(SubManagerLabel[index], sub.AddComponent<AudioSubManager>());
			//}
		}

		public void PlaySound(string group, string label, AudioDataBase data)
		{
			System.Play(group, label, data, 1, 1);
		}

		#endregion

		#region 生命周期

		#endregion


		#region 实现IBinary 的接口
		virtual public string SaveKey { get => throw new System.NotImplementedException(); set => throw new System.NotImplementedException(); }

		virtual public void Clear()
		{
			//停止所有音乐 清除内容
			system.StopAll(0);
		}

		virtual public void ReadSaveData(BinaryReader reader)
		{

		}

		virtual public void WriteSaveData(BinaryWriter writer)
		{
			
		}
		#endregion
	}
}